import * as actionTypes from './constants'
import {
  getDjRadioCateList,
  getGoodNewDjradio,
  getDjradioRank,
  getDjradioDetail,
  getDjradioPrograms
} from '@/services/djradio-api'
const changeDjRadioCateListAction = cateList => ({
  type: actionTypes.CHANGE_DJRADIO_CATELIST_ACTION,
  cateList
})
export const getDjRadioCateListAction = () => {
  return async dispatch => {
    const res = await getDjRadioCateList()
    dispatch(changeDjRadioCateListAction(res.categories))
  }
}
const changeCurrentIdAction = currentId => ({
  type: actionTypes.CHANGE_CURRENT_ID_ACTION,
  currentId
})
export const getCurrentIdAction = id => {
  return dispatch => {
    dispatch(changeCurrentIdAction(id))
  }
}
const changeNewGoodDjradioAction = newGoodDjradio => ({
  type: actionTypes.CHANGE_NEW_GOOD_DJRADIO_ACTION,
  newGoodDjradio
})
export const getNewGoodDjradioAction = id => {
  return async dispatch => {
    const res = await getGoodNewDjradio(id)
    dispatch(changeNewGoodDjradioAction(res.djRadios))
  }
}
const changeDjradioRankAction = djradioRank => ({
  type: actionTypes.CHANGE_DJRADIO_RANK_ACTION,
  djradioRank
})
const changeDjradioCountAction = djradioCount => ({
  type: actionTypes.CHANGE_DJRADIO_COUNT_ACTION,
  djradioCount
})
export const getDjradioRankAction = (id,offset) => {
  return async dispatch => {
    const res = await getDjradioRank(id, offset)
    dispatch(changeDjradioRankAction(res.djRadios))
    dispatch(changeDjradioCountAction(res.count))
  }
}
const changeDjradioDetailAction = djradioDetail => ({
  type: actionTypes.CHANGE_DJRADIO_DETAIL_ACTION,
  djradioDetail
})
export const getDjradioDetailAction = rid => {
  return async dispatch => {
    const res = await getDjradioDetail(rid)
    dispatch(changeDjradioDetailAction(res.djRadio))
  }
}
const changeDjradioProgramsAction = djradioPrograms => ({
  type: actionTypes.CHANGE_DJRADIO_PROGRAMS_ACTION,
  djradioPrograms
})
export const getDjradioProgramsAction = (rid, offset) => {
  return async dispatch => {
    const res = await getDjradioPrograms(rid, offset)
    dispatch(changeDjradioProgramsAction(res.programs))
  }
}